Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Module MODapplicationMain
	
	' Declare Functions ---------------------------------------------------------------------------------------------------------------------------------
	
	'UPGRADE_WARNING: Structure tSystemTime may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
	Private Declare Sub GetSystemTime Lib "Kernel32" (ByRef oSystemTime As tSystemTime)
	
	' Objects ---------------------------------------------------------------------------------------------------------------------------------
	
	Private fso As Scripting.FileSystemObject
	Private oLog As Scripting.TextStream
	
	' Types -----------------------------------------------------------------------------------------------------------------------------------
	
	Private Structure tSystemTime
		Dim iYear As Short
		Dim iMonth As Short
		Dim iDayOfWeek As Short
		Dim iDay As Short
		Dim iHour As Short
		Dim iMinute As Short
		Dim iSecond As Short
		Dim iMilliseconds As Short
	End Structure
	
	Private oSystemTime As tSystemTime
	
	' Constants -------------------------------------------------------------------------------------------------------------------------------
	
	Public Const iERROR As Short = 1
	Public Const iWARNING As Short = 2
	Public Const iINFO As Short = 3
	Public Const iDEBUG As Short = 4
	
	' Strings ---------------------------------------------------------------------------------------------------------------------------------
	
	Dim sData, sModule, sMessage, sVBerrorObjectDescription As String
	
	' Integers ----------------------------------------------------------------------------------------------------------------------------
	
	Dim iLevel As Short
	
	' Longs --------------------------------------------------------------------------------------------------------------------------------------
	
	Dim lVBerrorObjectNumber As Integer
	
	' begin code -----------------------------------------------------------------------------------------------------------------------------
	' Logger function ----------------------------------------------------------------------------------------------------------------------------
	
	Public Sub logMessage(ByRef iLevel As Short, ByRef sModule As String, ByRef sMessage As String, Optional ByRef sData As String = "", Optional ByRef lVBerrorObjectNumber As Integer = 0, Optional ByRef sVBerrorObjectDescription As String = "")
		
		Dim sDateTime As String
		
		sDateTime = Today & " " & TimeOfDay
		
		fso = New Scripting.FileSystemObject
		
		oLog = fso.OpenTextFile(sLogFilePath, Scripting.IOMode.ForAppending, True)
		
		oLog.WriteLine(iLevel & vbTab & Today & " " & TimeOfDay & vbTab & sModule & vbTab & sMessage & vbTab & Replace(sData, vbCrLf, "<LineBreak>") & vbTab & lVBerrorObjectNumber & vbTab & sVBerrorObjectDescription)
		
		oLog.Close()
		
		'UPGRADE_NOTE: Object oLog may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		oLog = Nothing
		
		'UPGRADE_NOTE: Object fso may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		fso = Nothing
		
	End Sub
	
	' Check version in registry and update registry if necessary -------------------------------------------------------------------
	
	Public Function checkVersion() As Object
		
		With New regOp
			
			.Root = regOp.RegRoot.HKEY_LOCAL_MACHINE
			.Key = "Software\bbd\AccessSearch"
			
			'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(version). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If .Value("version") <> "4.2" Then
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("version") = "4.2"
				.Key = "Software\bbd\AccessSearch\preferences"
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("columnWidths") = ""
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("defaultDatabasePath") = My.Application.Info.DirectoryPath & "\localStock.mdb"
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("defaultSearchField") = "partNumber"
				.Key = "Software\bbd\AccessSearch\preferences\remoteDB"
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("autoUpdate") = 1
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("fieldNames") = "partNumber,quantity,remark,manufacturer,dateCode"
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("serverAddress") = "example : http://SERVER_ADDRESS"
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("updatePagePath") = "example : FOLDER(s)/PAGE_NAME"
				'UPGRADE_WARNING: Couldn't resolve default property of object New (regOp).Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				.Value("databaseName") = "webStock.mdb"
			End If
			
		End With
		
	End Function
	
	' Create Unique Time stamp -------------------------------------------------------------------------------------------------------------------
	
	Public Function getUniqueTimeStamp() As String
		
		' call to API function to get current time
		
		GetSystemTime(oSystemTime)
		
		getUniqueTimeStamp = Year(Now) & "_" & Month(Now) & "_" & VB.Day(Now) & "_" & Hour(Now) & "_" & Minute(Now) & "_" & Second(Now) & "_" & oSystemTime.iMilliseconds
		
	End Function
	
	' Properties --------------------------------------------------------------------------------------------------------------------------------
	
	ReadOnly Property sLogFilePath() As String
		Get
			
			sLogFilePath = My.Application.Info.DirectoryPath & "/AccessSearch.log"
			
		End Get
	End Property
End Module